package com.work.demo.file;

import java.util.ArrayList;
import java.util.List;

public class Test {

	public static void main(String[] args) {

		List<String> phoneList = new ArrayList<>();

		for (int i = 0; i < 6000000; i++) {
			if (i == 5999) {
				phoneList.add("5324512515");
				continue;
			}
			phoneList.add(String.valueOf(i));
		}
		long begin = System.currentTimeMillis();
		System.out.println(begin);
		List<BloomFilter> bloomFilterList = new ArrayList<>();

		for (int i = 0; i < 20; i++) {
			BloomFilter bloom = new BloomFilter();
			bloomFilterList.add(bloom);
		}

		int s = 5000;
		//维护5000个在线用户
		for (int i = 0; i < s; i++) {
			int i1 = i % bloomFilterList.size();
			BloomFilter bloom = bloomFilterList.get(i1);
			if (i == 0) {
				bloom.addValue("5324512515");
				continue;
			}
			bloom.addValue(String.valueOf(i));
		}

		List<String> filterPhoneList = new ArrayList<>();

		for (int i = 0; i < phoneList.size(); i++) {
			String s1 = phoneList.get(i);
			for (int j = 0; j < bloomFilterList.size(); j++) {
				BloomFilter bloom = bloomFilterList.get(j);
				if (bloom.contains(s1)) {
					filterPhoneList.add(s1);
					break;
				}
			}
		}


		long end = System.currentTimeMillis();
		System.out.println(end);
		System.out.println("判断5324512515是否在线使用了:" + (begin - end));
		System.out.println(filterPhoneList.size());
	}

}
